/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

import database_beans.Zaposleni;
import static java.lang.StrictMath.log;
import java.util.ArrayList;
import java.util.HashMap;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author Alejandro
 */
@FacesConverter(value = "profConverter")
public class ProfConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
        
        HashMap<String, Zaposleni> pList = ((HashMap<String, Zaposleni>) ((UISelectItems) arg1.getChildren().get(0)).getValue());
        
        String s = "";
        int size = pList.size();
        for (int i = 0;i < size;i++) {
            Zaposleni  p = pList.get(Integer.toString(i));
            s = p.getKorisnik().getIme()+ " " + p.getKorisnik().getPrezime();
            if (s.equals(arg2)) {
                return p;
            }
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        String str = "";
        if (arg2 instanceof Zaposleni) {
            str = "" + ((Zaposleni) arg2).getKorisnik().getIme() + " " + ((Zaposleni) arg2).getKorisnik().getIme();
        }
        return str;
    }
}
